/**
 * 核心兼容库函数
 * @author yuhaya
 * @returns {MaoJs}
 */
function MaoJs(){

}
MaoJs.prototype.demo = function(){
	alert("this is test");
}

//通过类名来获得对象
MaoJs.prototype.getClass=function(classname,obj){
			var obj=obj||this;
			var reg=new RegExp("\b"+classname+"\b");
			var arr=[];
			 if(obj.getElementsByClassName){
			   return obj.getElementsByClassName(classname);
			 }else{
			   var alls=obj.getElementsByTagName("*");
			   for (var i=0; i<alls.length; i++) {
			     if(alls[i].className==classname||reg.test(alls[i].className)){
				   arr.push(alls[i]);
				 }
			   }
		return arr;
	}
}
//检查对象的类名是否包含指定的类
MaoJs.prototype.hasClass=function(classname,obj){
		 var obj=obj||this;
		 var objclass=obj.className;
		 var arr=objclass.split(/\s+/);
	     for (var i=0; i<arr.length; i++) {
			   if(arr[i]==classname){
			     return true;
			   }
	     }
		 return false;
};
	//获得/设置纯文本
MaoJs.prototype.getText=function(val,obj){
		  var obj=obj||this;
		  if(document.all){
			 if(val){
			   obj.innerText=val;
			 }else{
		       return obj.innerText;
			 }
		  }else{
		     if(val){
			   obj.textContent=val;
			 }else{
		       return  obj.textContent;
			 }
		  }
	};
//获取样式
MaoJs.prototype.getStyle=function(attr,obj){
			var obj=obj||this;
			 if(document.all){
			   return obj.currentStyle[attr];
			 }else{
			   return getComputedStyle(obj,null)[attr];
			 }
	};
//简单的动画函数
MaoJs.prototype.simpleAnimate=function(attr,end,speed,callback,obj){
			var obj=obj||this;
			if(obj.time){ clearInterval(obj.time);}//停止已经存在的定时器
		     var start=parseInt(obj.getStyle(attr));//获取初始值
			 var flag=start>end?false:true;//确定是变大还是缩小
		     obj.time=setInterval(function  () {
		        if(start==end){ clearInterval(obj.time);//满足条件停止动画
				if(callback){ callback();}  //如果有回调函数，执行回调函数
			   }else{     
				if(flag){//如果是变大的情况
					start+=speed;
					if(start>end){
					  start=end;}
				}else{//如果是变小的情况
				     start-=speed;
					if(start<end){
					  start=end;}
				}
				obj.style[attr]=start+"px";//把变化值赋值给样式
				}
			 },60)
	};
	//获取所有的子节点('元素节点')
MaoJs.prototype.getChilds=function(obj){
				 var obj=obj||this;
				 var childs=obj.childNodes;
				 var arr=[];
				 for (var i=0; i<childs.length; i++) {
					   if(childs[i].nodeType==3 || childs[i].nodeType==8 || childs[i].nodeType==2 || childs[i].nodeType==9){
					     continue;
					   }else{
					   arr.push(childs[i])
					   }
				 }
				 return arr;
	};
	//获取第一个子节点
MaoJs.prototype.getFirst=function(obj){
				  var obj=obj||this;
				  var first=obj.firstChild;
				  if(first==null){
				    return false;
				  }
				  while (first.nodeType==3) {
					   first=first.nextSibling;
					   if(first==null){
					     return false;
					   }
			     }
				 return first;
	};
	//获取最后一个子节点
MaoJs.prototype.getLast=function(obj){
		  var obj=obj||this;
		  var last=obj.lastChild;
		  if(last==null){
		    return false;
		  }
		  while (last.nodeType==3) {
			   last=last.previousSibling;
			   if(last==null){
			     return false;
			   }
	     }
		 return last;
	};
	//获取上一个兄弟节点
MaoJs.prototype.getUp=function(obj){
			  var obj=obj||this;
			  var up=obj.previousSibling;
			  if(up==null){
			    return false;
			  }
			  while (up.nodeType==3) {
				   up=up.previousSibling;
				   if(up==null){
				     return false;
				   }
		     }
			 return up;
	};
	//获取下一个兄弟节点
MaoJs.prototype.getNext=function(obj){
			  var obj=obj||this;
			  var next=obj.nextSibling;
			  if(next==null){
			    return false;
			  }
			  while (next.nodeType==3) {
				   next=next.nextSibling;
				   if(next==null){
				     return false;
				   }
		     }
			 return next;
	};
	//插入到某个元素之后
MaoJs.prototype.insertAfter=function(afterobj,parent,obj){
			var obj=obj||this;
			var next= afterobj.getNext();
	 	  	if(!next){
		   		parent.appendChild(obj)
		  	}else{
		   		parent.insertBefore(obj,next);
		   	}
	};
	//判断某个元素是否包含有另外一个元素
MaoJs.prototype.contains=function(child,parent){
			var parent=parent||this;
			if(parent.contains){
		     	return parent.contains(child) && parent!=child;
			}else{
		  		return (parent.compareDocumentPosition(child)===20);
			}
	};
	//获得事件对象
MaoJs.prototype.getEvent=function(e){
			return e||window.event;
	};
	//判断鼠标是否真正的从外部移入，或者是真正的移出到外部；
MaoJs.prototype.checkHover=function(e,target){
			var target = target||this;
			if(getEvent(e).type=="mouseover"){
		    	return !target.contains(getEvent(e).relatedTarget || getEvent(e).fromElement)&&!((getEvent(e).relatedTarget || getEvent(e).fromElement)===target);
		 	}else{
				return !target.contains(getEvent(e).relatedTarget || getEvent(e).toElement)&&!((getEvent(e).relatedTarget || getEvent(e).toElement)===target);
			}
	};
	//鼠标移入移除事件
	/*
	  obj   要操作的对象
	  overfun   鼠标移入需要处理的函数
	  outfun     鼠标移除需要处理的函数
	*/
MaoJs.prototype.hover=function(overfun,outfun,obj){
			var obj=obj||this;
			if(overfun){
		    	obj.onmouseover=function  (e) {
				  if(obj.checkHover(e)){
				     overfun.call(obj);
				  }
		    	}
		 	}
		  	if(outfun){
		    	obj.onmouseout=function  (e) {
				  if(obj.checkHover(e)){
				     outfun.call(obj);
				  }
		    }
		  }
	};
	//鼠标滚轮事件(ie9和360极速浏览器不支持)
	/*
	   obj--需要操作的对象
	   unfun  鼠标向上滚动的时候的处理函数
	   downfun  鼠标向下时候的处理函数
	*/
MaoJs.prototype.mouseScroll=function(upfun,downfun,obj){
			 var obj=obj||this;
			 if(obj.addEventListener){
				obj.addEventListener("DOMMouseScroll",changefun,false)
			 }else{
			 	obj.onmousewheel=changefun;
	         }
	         function changefun (e) {
		    	var ev=e||window.event;
	        	var num=ev.wheelDelta || ev.detail;
	           	if(num==120 ||num==-3){
			      if(upfun){
				     upfun()
				  }
			   	}
			   	if(num==-120 ||num==3){
			      if(downfun){
				     downfun()
				  }
			   }
	       }
	};
	//live添加事件
	/*
	   obj  要处理的对象
	   evtype  事件类型
	   fun     事件处理程序
	   gettype  执行程序的类型
	*/
MaoJs.prototype.live=function(evtype,fun,gettype,obj){
			var obj = obj||this;
			//默认的类型
			var gettype=gettype||"name";
		    //先找到父元素
			var parent=obj.parentNode;
			//给父元素添加事件
			parent["on"+evtype]=function  (e) {
			  var ev=e||window.event;
			  var target=ev.target||ev.srcElement;
			  if(gettype=="name"){
			     if(target.nodeName==obj.nodeName){
				   if(fun){
				     fun.call(target,target);
				   }
				 }
			  }
			  if(gettype=="class"){
			     if(target.className==obj.className){
				   if(fun){
				     fun.call(target,target);
				   }
				 }
			  }
			  if(gettype=="id"){
			     if(target.id==obj.id){
				   if(fun){
				     fun.call(target,target);
				   }
				 }
			  }
			}
	};
	//设置或者获取css
MaoJs.prototype.css=function(attr,val,obj){
		var obj = obj||this;
	    if(obj.nodeType!==1){
		 return false;
		}
		//修正参数
	    var attr=attr.replace(/^\s*|\s*$/g,"");
		//获取属性值
		if(arguments.length==1){
		   if(attr=="opacity"){   
			return parseInt(obj.currentStyle?(obj.currentStyle[attr]==undefined?1:obj.currentStyle[attr]):(getComputedStyle(obj,null)[attr]==undefined?1:getComputedStyle(obj,null)[attr]))*100;
		   }

		   if(attr=="top"||attr=="left"||attr=="width"||attr=="height"){
		     //修正参数
	         var str=attr.charAt(0);
			 var attr="offset"+attr.replace(attr.charAt(0),str.toUpperCase());
			return obj[attr];
		   }

		   return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,null)[attr]
		  
		}

	    //设置值
		if(arguments.length>=2){
		  switch (attr) {
		  case "top":
		  case "left":
		  case "width":
		  case "height":
		  obj.style[attr]=val+"px";
		  break;
		  case "opacity":
		  obj.style.filter="alpha(opacity="+val+")";
		  obj.style[attr]=val/100;
	     break;
		 default:
		 obj.style[attr]=val;
		  }
		}
	};
MaoJs.getVersions=function(){
	    var imyeah={};
	    var ua=navigator.userAgent.toLowerCase();
	    var s;
	    (s=ua.match(/msie ([\d.]+)/)) ? imyeah.ie=document.documentMode :
	    (s=ua.match(/firefox\/([\d.]+)/)) ? imyeah.firefox=s[1] :
	    (s=ua.match(/chrome\/([\d.]+)/)) ? imyeah.chrome=s[1] :
	    (s=ua.match(/opera.([\d.]+)/)) ? imyeah.opera=s[1] :
	    (s=ua.match(/version\/([\d.]+).*safari/)) ? imyeah.safari=s[1] : 0;
	    var mes = new Array();
	    if(imyeah.ie){
	        mes[0] = 'IE';
	        mes[1] = imyeah.ie;        
	    }
	    
	    if(imyeah.firefox){
	        mes[0] = 'Firefox';
	        mes[1] = imyeah.firefox;
	    }
	    if(imyeah.chrome){
	        mes[0] = 'Chrome';
	        mes[1] = imyeah.chrome;
	    }
	    if(imyeah.opera){
	        mes[0] = 'Opera';
	        mes[1] = imyeah.opera;
	    }
	    if(imyeah.safari){
	        mes[0] = 'Safari';
	        mes[1] = imyeah.safari;
	    }
	    return mes;
	};
	//核心动画函数
	/*
	  函数的四个参数分别代表：
					t--- current time（当前时间）；0 +=60
					b--- beginning value（初始值）；
					c--- change in value（变化量）；end-start
					d---duration（持续时间）  5000
					*/
MaoJs.prototype.animate=function(attr,dur,fn,callback,obj){
			var obj = obj||this;
	 		if(hasOwnProperty.call(obj,'time') && obj.time != 0){
	                    return;
			           //防止动画进行时多次点击
		           }        
			    var start=[];
				var changes=[];
				var t=0;
				for (var i in attr) {
				  start[i]=obj.css(i);
				  changes[i]=attr[i]-start[i];
				}
	        
		    obj.time=setInterval(function  () {
			  var flag=true;
			  if(t<=dur){
				   flag=false;
				  for (var i in attr) {
					obj.css(i,fn(t,start[i],changes[i],dur))
				  }
				  t+=60;
			  }

			  if(flag){
			    clearInterval(obj.time);
	            if(getVersions()[0]=='IE' && (getVersions()[1]==6.0 || getVersions()[1]==7.0))
	              { 
	                obj.time = 0; 
	              }else{
	                delete obj.time;
	              }                       
				 for (var i in attr) {
					obj.css(i,attr[i])
				 };
					if(callback){
					  callback();
				 }
			    }
		    },60)
	}
//判断通过便签获取的dom对象是否存在
MaoJs.prototype.exist = function(){ 
    if(typeof this !='undefined' && this.length>=1){
        return true;
    }
 
    return false;
};
MaoJs.Tween={
	    Linear: function(t,b,c,d){ return c*t/d + b; },
	    Quad: {
	        easeIn: function(t,b,c,d){
	            return c*(t/=d)*t + b;
	        },
	        easeOut: function(t,b,c,d){
	            return -c*(t/=d)*(t-2) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if ((t/=d/2) < 1) return c/2*t*t + b;
	            return -c/2 * ((--t)*(t-2) - 1) + b;
	        }
	    },
	    Cubic: {
	        easeIn: function(t,b,c,d){
	            return c*(t/=d)*t*t + b;
	        },
	        easeOut: function(t,b,c,d){
	            return c*((t=t/d-1)*t*t + 1) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if ((t/=d/2) < 1) return c/2*t*t*t + b;
	            return c/2*((t-=2)*t*t + 2) + b;
	        }
	    },
	    Quart: {
	        easeIn: function(t,b,c,d){
	            return c*(t/=d)*t*t*t + b;
	        },
	        easeOut: function(t,b,c,d){
	            return -c * ((t=t/d-1)*t*t*t - 1) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
	            return -c/2 * ((t-=2)*t*t*t - 2) + b;
	        }
	    },
	    Quint: {
	        easeIn: function(t,b,c,d){
	            return c*(t/=d)*t*t*t*t + b;
	        },
	        easeOut: function(t,b,c,d){
	            return c*((t=t/d-1)*t*t*t*t + 1) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	            return c/2*((t-=2)*t*t*t*t + 2) + b;
	        }
	    },
	    Sine: {
	        easeIn: function(t,b,c,d){
	            return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	        },
	        easeOut: function(t,b,c,d){
	            return c * Math.sin(t/d * (Math.PI/2)) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	        }
	    },
	    Expo: {
	        easeIn: function(t,b,c,d){
	            return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	        },
	        easeOut: function(t,b,c,d){
	            return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if (t==0) return b;
	            if (t==d) return b+c;
	            if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
	            return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	        }
	    },
	    Circ: {
	        easeIn: function(t,b,c,d){
	            return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	        },
	        easeOut: function(t,b,c,d){
	            return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	        },
	        easeInOut: function(t,b,c,d){
	            if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
	            return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	        }
	    },
	    Elastic: {
	        easeIn: function(t,b,c,d,a,p){
	            if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	            if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	            else var s = p/(2*Math.PI) * Math.asin (c/a);
	            return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	        },
	        easeOut: function(t,b,c,d,a,p){
	            if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	            if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	            else var s = p/(2*Math.PI) * Math.asin (c/a);
	            return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
	        },
	        easeInOut: function(t,b,c,d,a,p){
	            if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
	            if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	            else var s = p/(2*Math.PI) * Math.asin (c/a);
	            if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	            return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	        }
	    },
	    Back: {
	        easeIn: function(t,b,c,d,s){
	            if (s == undefined) s = 1.70158;
	            return c*(t/=d)*t*((s+1)*t - s) + b;
	        },
	        easeOut: function(t,b,c,d,s){
	            if (s == undefined) s = 1.70158;
	            return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	        },
	        easeInOut: function(t,b,c,d,s){
	            if (s == undefined) s = 1.70158; 
	            if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	            return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	        }
	    },
	    Bounce: {
	        easeIn: function(t,b,c,d){
	            return c - MaoJs.Tween.Bounce.easeOut(d-t, 0, c, d) + b;
	        },
	        easeOut: function(t,b,c,d){
	            if ((t/=d) < (1/2.75)) {
	                return c*(7.5625*t*t) + b;
	            } else if (t < (2/2.75)) {
	                return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	            } else if (t < (2.5/2.75)) {
	                return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	            } else {
	                return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	            }
	        },
	        easeInOut: function(t,b,c,d){
	            if (t < d/2) return MaoJs.Tween.Bounce.easeIn(t*2, 0, c, d) * .5 + b;
	            else return MaoJs.Tween.Bounce.easeOut(t*2-d, 0, c, d) * .5 + c*.5 + b;
	        }
	    }
	 };